import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/widgets/app/app_shop_item_card.dart';
import 'package:bxultimate/widgets/mk_empty.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class ShopCategoryListPage extends StatefulWidget {
  const ShopCategoryListPage({Key? key}) : super(key: key);

  @override
  State<ShopCategoryListPage> createState() => _ShopCategoryListPageState();
}

class _ShopCategoryListPageState extends State<ShopCategoryListPage> {
  final controller = Get.find<ShopCategoryListController>();
  final state = Get.find<ShopCategoryListController>().state;

  var count = 0;

  @override
  Widget build(BuildContext context) {
    return MkPage(
      child: Obx(() => Scaffold(
            backgroundColor: Colors.transparent,
            appBar: TDNavBar(
              backgroundColor: Colors.transparent,
              title: state.title,
            ),
            body: _buildBody(),
          )),
    );
  }

  _buildBody() {
    return Padding(
      padding: EdgeInsets.only(
          left: AppTheme.iDefaultPadding, right: AppTheme.iDefaultPadding),
      child: EasyRefresh(
        // 下拉样式
        header: TDRefreshHeader(),
        footer: TaurusFooter(),
        child: Obx(() => Column(
              children: [
                ...state.shopList.map((e) => AppShopItemCard(shop: e)).toList()
              ],
            )),
        // 下拉刷新回调
        onRefresh: controller.onRefresh,
        onLoad: controller.onLoad,
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<ShopCategoryListController>();
    super.dispose();
  }
}
